package com.celeritymq.message;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;

public abstract class CelerityMessage implements Message, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4626299651202002144L;
	private Destination destination;
	private Destination replyTo;
	private String correlationID;
	private String messageId;
	private int priority;
	private int deliveryMode;
	private long expirationTime;
	private boolean redelivered;
	private String jmsType;
	private Map<String, Object> propertyMap = new HashMap<String, Object>();

	protected CelerityMessage(String messageId, String correlationID, Destination destination, int priority, int deliveryMode,
			long expirationTime) {
		this.messageId = messageId;
		this.correlationID = correlationID;
		this.destination = destination;
		this.priority = priority;
		this.expirationTime = expirationTime;
		this.deliveryMode = deliveryMode;
	}

	public void setReplyTo(Destination replyTo) {
		this.replyTo = replyTo;
	}

	public Destination getReplyTo() {
		return replyTo;
	}

	@Override
	public void acknowledge() throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void clearProperties() throws JMSException {
		propertyMap.clear();
	}

	private Object getValue(String name, Class clz) {
		Object value = propertyMap.get(name);
		if (value.getClass() == clz) {
			return value;
		}
		return null;
	}

	@Override
	public boolean getBooleanProperty(String name) throws JMSException {
		return (Boolean) getValue(name, Boolean.class);
	}

	@Override
	public byte getByteProperty(String name) throws JMSException {
		return (Byte) getValue(name, Byte.class);
	}

	@Override
	public double getDoubleProperty(String name) throws JMSException {
		return (Double) getValue(name, Double.class);
	}

	@Override
	public float getFloatProperty(String name) throws JMSException {
		return (Float) getValue(name, Float.class);
	}

	@Override
	public int getIntProperty(String name) throws JMSException {
		return (Integer) getValue(name, Integer.class);
	}

	@Override
	public String getJMSCorrelationID() throws JMSException {
		return correlationID;
	}

	@Override
	public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
		return correlationID.getBytes();
	}

	@Override
	public int getJMSDeliveryMode() throws JMSException {
		return deliveryMode;
	}

	@Override
	public Destination getJMSDestination() throws JMSException {
		return destination;
	}

	@Override
	public long getJMSExpiration() throws JMSException {
		return expirationTime;
	}

	@Override
	public String getJMSMessageID() throws JMSException {
		return messageId;
	}

	@Override
	public int getJMSPriority() throws JMSException {
		return priority;
	}

	@Override
	public boolean getJMSRedelivered() throws JMSException {
		return redelivered;
	}

	@Override
	public Destination getJMSReplyTo() throws JMSException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getJMSTimestamp() throws JMSException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getJMSType() throws JMSException {
		return jmsType;
	}

	@Override
	public long getLongProperty(String name) throws JMSException {
		return (Long) getValue(name, Long.class);
	}

	@Override
	public Object getObjectProperty(String name) throws JMSException {
		return getValue(name, Object.class);
	}

	@Override
	public Enumeration<String> getPropertyNames() throws JMSException {
		Vector<String> vector = new Vector<String>();
		vector.addAll(propertyMap.keySet());
		return vector.elements();
	}

	@Override
	public short getShortProperty(String name) throws JMSException {
		return (Short) getValue(name, Short.class);
	}

	@Override
	public String getStringProperty(String name) throws JMSException {
		return (String) getValue(name, String.class);
	}

	@Override
	public boolean propertyExists(String name) throws JMSException {
		return propertyMap.containsKey(name);
	}

	@Override
	public void setBooleanProperty(String name, boolean arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setByteProperty(String name, byte arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setDoubleProperty(String name, double arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setFloatProperty(String name, float arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setIntProperty(String name, int arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSCorrelationID(String arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSCorrelationIDAsBytes(byte[] arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSDeliveryMode(int arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSDestination(Destination arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSExpiration(long arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSMessageID(String messageId) throws JMSException {
		this.messageId = messageId;
	}

	@Override
	public void setJMSPriority(int priority) throws JMSException {
		this.priority = priority;
	}

	@Override
	public void setJMSRedelivered(boolean redelivered) throws JMSException {
		this.redelivered = redelivered;
	}

	@Override
	public void setJMSReplyTo(Destination replyTo) throws JMSException {
		this.replyTo = replyTo;
	}

	@Override
	public void setJMSTimestamp(long arg0) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setJMSType(String jmsType) throws JMSException {
		this.jmsType = jmsType;
	}

	@Override
	public void setLongProperty(String name, long value) throws JMSException {
		propertyMap.put(name, value);
	}

	@Override
	public void setObjectProperty(String name, Object arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setShortProperty(String name, short arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

	@Override
	public void setStringProperty(String name, String arg1) throws JMSException {
		// TODO Auto-generated method stub

	}

}
